package demo;

import java.util.ArrayList;
import java.util.List;

/**
 * 无重复字符的最长子串
 */
class Solution2 {
	public int lengthOfLongestSubstring(String s) {
		int length = s.length();
		int result = 0;
		for (int i = 0; i < length; i++) {
			List<Character> characters = new ArrayList<>();
			for (int j = i; j < length; j++) {
				char c = s.charAt(j);
				if (characters.contains(c)) {
					break;
				} else {
					characters.add(c);
				}
			}
			int newLength = characters.size();
			result = newLength > result ? newLength : result;
		}
		return result;
	}
}

